
var Error = function(obj) {
	this.class = 'Error';
	obj = obj || {};
	
	this.id = obj.id || "";
	this.code = obj.code || 0;
	this.message = obj.message || "";
};

Error.prototype.toXML = function() {
	var xml = '<error code="' + this.code + '" message="' + this.message '"/>';
	
	return xml;
};

Error.prototype.fromXML = function(xml) {
	xml = xml.replace(/\r\n|\n/g, ''); // remove line breaks
	
	var codeM = xml.match(/code="(\S+)"/i) || [];
	var messageM = xml.match(/message="(\S+)"/i) || [];
	
	this.code = codeM[1] || 0;
	this.message = messageM[1] || "";
	
	return this;
};

module.exports = Error;